#!/bin/bash
#
# Copyright (C) 2013 rdrrlabs gmail com,
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

export CMD_ARGS=""

export VERB="test"

if [[ "$1" == "-i" ]]; then
    export CMD_ARGS="-i"
    shift
fi
if [[ -z "$1" ]]; then
    export PKGS=$(find src -name "*_test.go" | sed -e 's@src/@@' -e 's@/[a-z0-9_-]\+_test.go$@@' | sort | uniq)
fi

if [[ $(uname -o) == "Cygwin" ]]; then
	export GOPATH=$(cygpath -w "$PWD")
else
	export GOPATH="$PWD"
fi

# Linux
function wrap_py27_exec() {
    # remove the AE go version from the path
    GOAE=~/google/go_appengine
    PATH=${PATH/$GOAE:/}
    # add the default one
    if [[ -x ~/go/bin/go ]]; then
        export PATH=~/go/bin/go:$PATH
        echo "[PATH] remove go_appengine, add regular go"
        #--echo "[PATH] Changed to $PATH"
    fi
    echo go $VERB -v $CMD_ARGS $* $PKGS
    go $VERB -v $CMD_ARGS $* $PKGS && echo "[+EXIT] code $?" || echo "[-EXIT] code $?"
}

. ./_wrap_py27.sh

